<template>
  <div class="header_bottom" v-resize="onResize"></div>
  <div class="header" :style="{ left: 'calc(100vw - ' + clientWidth + 'px - 10px)' }">
    <div class="header_title">
      <slot name="title"></slot>
    </div>
    <div class="header_btns">
      <slot name="header_flex"></slot>
      <el-button v-if="props.showButton" type="info" @click.stop="goBack">{{ backText }}</el-button>
      <slot name="header_btns"></slot>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { useI18n } from 'vue-i18n'
const { t } = useI18n() // 中英文
const clientWidth = ref(document.querySelector('.main-box').offsetWidth)
const onResize = () => {
  clientWidth.value = document.querySelector('.main-box').offsetWidth
}
const props = defineProps({
  showButton: {
    type: Boolean,
    default: true
  },
  backTextShow: {
    type: Boolean,
    default: true
  },
  backText: {
    type: String,
    default: '返回'
  }
})

const goBack = () => {
  window.history.back(-1)
}
</script>

<style lang="scss" scoped>
.header_bottom {
  height: 50px;
  width: 100%;
}
.header {
  height: 54px;
  position: fixed;
  top: 0;
  right: 10px;
  z-index: 100;
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
  background: #ffffff;
  &::after {
    content: '';
    width: 100%;
    height: 1px;
    position: absolute;
    bottom: 0;
    border-bottom: 1px var(--el-border-color) var(--el-border-style);
  }
  .header_title {
    font-size: 16px;
    font-weight: 550;
    color: var(--el-text-color-primary);
    margin-left: 32px;
  }
  .header_btns {
    margin-right: 16px;
    display: flex;
    align-items: center;
  }
}
</style>
